<template>
  <div>
    动态业务
    <DataGrid ref="grid" :columns="columns" :action="api">
      <a
        slot="action"
        slot-scope="{ row, column, index }"
        @click="vitem().hi(row)"
      >
        hi {{ index }} 
      </a>
    </DataGrid>
    <Modal
      v-model="box.show"
      :title="box.title"
      width="1200"
      footer-hide
      @on-visible-change="mclose"
    >
      <component
        :is="box.detail"
        :api="api"
        :row="box.row"
        @on-close="cancel"
        @on-ok="ok"
      />
    </Modal>
  </div>
</template>

<script>
import Api from "@/api/base";
export default {
  data() {
    return {
      list: [],
      api: null,
      box: {
        row: null,
        title: "",
        show: false,
        width: 1200,
        detail: null,
      },
    };
  },
  components: {},
  async asyncData(context) {
    let api = new Api("/api/Atom");
    let { result } = await api.info(); // 加载数据字典
    let columns = result.columns
      .filter((u) => {
        return u.dataType != "json";
      })
      .map((u) => {
        var col = {
          key: u.propertyName.charAt(0).toLowerCase() + u.propertyName.slice(1),
          title: u.columnDescription,
          hide: u.baseType > 1,
        };
        if (u.code) {
          col.code = u.code;
        }
        return col;
      });
    columns.push({
      key: "Action",
      title: "操作",
      slot: "action",
    });
    console.log(columns);
    api.base = result;
    return { api, columns };
  },
  created() {
    // this.api = new Api("/api/department");
    //  this.load();
  },
  methods: {
    load() {
      var paras = {
        fields: "name,code",
        conditions: this.$u.conditions({
          base: "Table",
          status: 1,
        }),
      };
      this.api.list(paras).then((r) => {
        this.list = r.result;
      });
    },
    ok() {
      this.$refs.grid.load();
      this.modal = false;
      this.curId = null;
    },
     cancel() {
      this.curId = null;
      this.modal = false;
    },
     mclose(v) {
      if (!v) {
        this.box.show = false;
      }
    },
    hi(r) {},
    vitem() {
      let that = this;
      let m = {
        show(r) {
          alert(r.id);
        },
        hi(r) {
        //   that.box = {
        //     row: r,
        //     title: "hi",
        //     show: true,
        //     width: 1200,
        //     detail: ()=>import('./add'),
        //   };
          that.$router.push("/bus/"+r.entityName)
         },
      };
      return m;
    },
  },
};
</script>

<style style="less">
</style>
